"""empty message

Revision ID: bcf2a9657162
Revises: b6cbcf622c0a
Create Date: 2025-04-29 12:52:04.880611

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
# Update profile_type column and clean up active_user_record statuses
# This migration updates the profile_type column in the user_profile table to include
# a descriptive comment and modifies its properties. Additionally, it performs a data
# cleaning operation on the active_user_record table, updating statuses from 0 to 4101.
revision = "bcf2a9657162"
down_revision = "b6cbcf622c0a"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="0 default, 1 system configuration, 2 user configuration, 3 course configuration",
            existing_nullable=False,
            existing_server_default=sa.text("'0'"),
        )
        # Data cleaning operation
        op.execute("UPDATE active_user_record SET status = 4101 WHERE status = 0")

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="0 default, 1 system configuration, 2 user configuration, 3 course configuration",
            existing_nullable=False,
            existing_server_default=sa.text("'0'"),
        )
        # Revert data cleaning operation
        op.execute("UPDATE active_user_record SET status = 0 WHERE status = 4101")
